/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 script_stack_action.h

	$Header: /heroes4/script_stack_action.h $

	$NoKeywords: $

 ************************************************************************/


#ifndef _HDR_SCRIPT_STACK_ACTION
#define _HDR_SCRIPT_STACK_ACTION

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "script_targeted_action.h"
#include "streambuf_operators.h"
#include "script_targeting.h"
#include "hero.h"
#include "army.h"
#include "town.h"

class t_script_stack_action : 
	public t_script_targeted_action< t_script_stack_target >
{
public:
	virtual void	execute(t_script_context_hero const& context ) const;
	virtual void	execute(t_script_context_town const& context ) const;
	virtual void	execute(t_script_context_object const& context ) const;
	virtual void	execute(t_script_context_army const& context ) const;
	virtual void	execute(t_script_context_global const& context ) const;

protected:
	virtual void	make_adjustment(t_creature_stack* stack, t_creature_array* owning_array) const = 0;
	virtual void	make_adjustment(t_creature_array* array) const = 0;
};

inline void t_script_stack_action::execute(t_script_context_hero const& context) const
{
	if (get_target() == k_script_stack_target_this) 
	{
		make_adjustment(context.hero, context.army);
	}
	else
	{
		t_creature_array* target = select_creature_array_by_target(get_target(), NULL, context.army, context.opposing_army);
		make_adjustment(target);
	}
}

inline void t_script_stack_action::execute(t_script_context_town const& context) const
{
	t_creature_array* target = select_creature_array_by_target(get_target(), context.garrison, NULL, context.opposing_army);
	make_adjustment(target);
}

inline void t_script_stack_action::execute(t_script_context_object const& context) const
{
	assert(false);
}

inline void t_script_stack_action::execute(t_script_context_army const& context) const
{
	t_creature_array* target = select_creature_array_by_target(get_target(), NULL, context.army, context.opposing_army);
	make_adjustment(target);
}

inline void t_script_stack_action::execute(t_script_context_global const& context) const
{
	assert(false);
}

#endif 
